require 'gosu'

class Gosu::Song
  def safe_play(*args)
    play(*args) 
  end
  
  def safe_pause(*args)
    pause(*args) rescue nil
  end
  
  def safe_stop(*args)
    stop(*args) rescue nil
  end
end

class Gosu::Sample
  def safe_play(*args)
    play(*args) rescue nil
  end
end

class Gosu::Font
  SHADOW_X_FACTOR=1.3
  SHADOW_Y_FACTOR=1.2
  def shadow_text(text,x,y,z,factor_x, factor_y,color)
    offset_x=0
    s_factor_x=factor_x * SHADOW_X_FACTOR
    s_factor_y=factor_y * SHADOW_Y_FACTOR
    text.scan( /./ ) do |letter|
      draw(letter,x+offset_x,y,z,factor_x,factor_y,color)
      draw_rel(letter,x+offset_x,y,z-1,0.075,0.075,s_factor_x,s_factor_y,0xFF000000)
      
      offset_x +=text_width(letter, s_factor_x) + 3   
    end
  end
  
  def get_max_factor(text,init_factor,target_width,use_shadow=false)    
    final_factor=init_factor
    multiplier = use_shadow ? SHADOW_X_FACTOR : 1
    final_factor -= 0.25 while(text_width(text,final_factor * multiplier) > target_width)
    final_factor
  end
end

def cur_dir
  File.dirname(__FILE__)
end
